<template>
  <div
    class="page_body"
    v-loading.fullscreen.lock="loadingKey"
    :element-loading-text="loadingText"
  >
    <!-- 面包屑 -->
    <el-row>
      <el-col :span="24" class="page_box_top">
        <i class="el-icon-s-fold"></i>
        <el-breadcrumb separator="/" class="page_box_top_nav">
          <el-breadcrumb-item class="breadcrumb_active_item"
            >教练员</el-breadcrumb-item
          >
          <el-breadcrumb-item>认证答题记录</el-breadcrumb-item>
        </el-breadcrumb>
      </el-col>
    </el-row>
    <el-row>
      <div class="coachTrain_order_content">
        <!-- 搜索框 -->
        <el-row>
          <el-col :span="24">
            <div class="coachTrain_order_search">
              <el-input
                v-model="searchKey"
                placeholder="请输入关键词"
                style="width: 200px; margin-left: 10px"
                size="mini"
              ></el-input>
              <el-button
                type="primary"
                size="mini"
                style="margin-left: 5px"
                @click="searchFn()"
                >搜索</el-button
              >
            </div>
          </el-col>
        </el-row>
        <!-- 数据列表 -->
        <el-row
          type="flex"
          justify="center"
          v-if="orderListData != undefined && orderListData.length > 0"
        >
          <el-col :span="24">
            <el-table
              :data="orderListData"
              border
              style="width: 100%"
              size="mini"
              :cell-style="cellStyleFn"
            >
              <el-table-column
                type="index"
                label="序号"
                width="50"
                align="center"
              >
              </el-table-column>

              <!-- <el-table-column
                prop="order_number"
                label="订单编号"
                width="220"
                align="center"
              ></el-table-column> -->

              <el-table-column
                prop="title"
                label="考试名称"
                align="center"
                min-width="220"
              ></el-table-column>

              <el-table-column
                prop="name"
                label="学员名称"
                width="160"
                align="center"
              ></el-table-column>

              <el-table-column
                prop="correct_num"
                label="正确数量"
                width="220"
                align="center"
              ></el-table-column>

              <el-table-column
                prop="error_num"
                label="错误数量"
                align="center"
                width="180"
              ></el-table-column>

              <el-table-column
                prop="score"
                label="分数"
                width="100"
                align="center"
              ></el-table-column>

              <el-table-column
                prop="pass_status"
                label="通过状态"
                width="120"
                align="center"
                :formatter="formatterStatusFn"
              ></el-table-column>

              <el-table-column
                prop="created_at"
                label="考试时间"
                width="180"
                align="center"
              ></el-table-column>

              <el-table-column label="操作" width="140" align="center">
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="primary"
                    @click="detailFn(scope.$index, scope.row)"
                    >查看</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-col>
        </el-row>
        <el-row
          type="flex"
          justify="center"
          v-if="orderListData != undefined && orderListData.length > 0"
        >
          <el-col :span="24">
            <div class="coachTrain_order_pagination">
              <el-pagination
                @size-change="listSizeChange"
                @current-change="listCurrentChange"
                :current-page="currentPage"
                :page-sizes="pageSizes"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
              >
              </el-pagination>
            </div>
          </el-col>
        </el-row>
        <el-row v-else>
          <el-empty description="暂无订单"></el-empty>
        </el-row>
      </div>
    </el-row>
    <!-- 简单题详情 -->
    <el-dialog
      title="简单题"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <div class="question">{{ shortQuestion }}</div>
      <div class="answer">{{ shortAnswer }}</div>
      <span slot="footer" class="dialog-footer">
        <!-- <el-button @click="dialogVisible = false">取 消</el-button> -->
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<style src="../../assets/css/order/coachTrainOrder.css" scoped></style>

<script>
export default {
  name: "CoachTrainOrder",
  components: {},
  data() {
    return {
      orderListData: [], // 订单列表数据
      currentPage: 1, // 当前页
      pageSizes: [10, 20, 50, 100], // 可选页容量
      pageSize: 10, // 当前页容量
      total: 0, // 总条数
      searchKey: "", //搜索关键词
      checkedLevel: "", // 筛选-等级
      levelList: [], // 等级列表
      orderStatusList: [
        {
          value: 1,
          label: "已通过",
        },
        {
          value: 2,
          label: "未通过",
        },
      ],
      loadingKey: false,
      loadingText: "",
      checkedOrderStatus: "", // 筛选-订单状态
      dialogVisible: false, // 简单题详情弹窗
      shortQuestion: "", //简单题题目
      shortAnswer: "", //简单题回答
    };
  },
  created: function () {
    this.getListDataFn();
  },
  methods: {
    // 搜索按钮
    searchFn: function () {
      this.currentPage = 1;
      this.getListDataFn();
    },
    // 等级筛选
    checkedLevelChange: function (val) {
      this.checkedLevel = val;
      this.getCheckedExamListFn();
    },
    // 订单状态筛选
    checkedOrderStatusChange: function (val) {
      this.checkedOrderStatus = val;
    },
    // 查询列表数据
    getListDataFn: function () {
      let that = this;
      let url = "/admin/coachanswer/index";
      let data = {
        keywords: this.searchKey,
        page: this.currentPage,
        perPage: this.pageSize,
      };
      that.loadingText = "加载中...";
      that.loadingKey = true;
      this.axios
        .post(url, data)
        .then((response) => {
          that.loadingKey = false;
          if (response.code == 0) {
            that.orderListData = response.list;
            that.total = response.total_count;
          } else {
            that.$message.error(response.msg);
          }
        })
        .catch(function (error) {
          that.loadingKey = false;
          console.log(error);
        });
    },
    // 设置单元格字体颜色
    cellStyleFn: function ({ row, columnIndex }) {
      let style = "";
      if (columnIndex == 5) {
        style = "color: #F6705E";
      }
      if (columnIndex == 6) {
        if (row.order_status == 1 || row.order_status == 6) {
          style = "color: #F6705E";
        } else {
          style = "color: #8ECF5F";
        }
      }
      return style;
    },
    // 订单状态格式化
    formatterStatusFn: function (row) {
      let passStatus = row.pass_status;
      let text = "";
      this.orderStatusList.forEach(function (item) {
        if (item.value == passStatus) {
          text = item.label;
        }
      });
      return text;
    },
    // 等级格式化
    formatterLeveFn: function (row) {
      let exam_level = row.exam_level;
      let text = "";
      this.levelList.forEach(function (item) {
        if (item.key == exam_level) {
          text = item.value;
        }
      });
      return text;
    },
    // 页容量改变
    listSizeChange: function (val) {
      this.currentPage = 1;
      this.pageSize = val;
      this.getListDataFn();
    },
    // 当前页改变
    listCurrentChange: function (val) {
      this.currentPage = val;
      this.getListDataFn();
    },
    // 查看详情
    detailFn: function (index, row) {
      this.shortQuestion = row.short_question;
      this.shortAnswer = row.short_answer;
      this.dialogVisible = true;
    },
  },
};
</script>
